package com.local.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.local.model.LocalStation;
import com.local.service.face.LocalStationService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;
import com.qianhai.common.entity.PageInfo;

@RestController
@RequestMapping(value = "/admin/station", method = RequestMethod.POST)
public class LocalStationController extends BaseController
{
	@Autowired
	private LocalStationService localStationService;
	
	@RequestMapping(value = "/modifyStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap modifyStation(@RequestBody LocalStation localStation)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStationService.modifyLocalStation(localStation);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	

	/**
	 * 
	 * 方法描述：添加岗亭记录
	 * @Title: addSentryBox 
	 * @param @param localStation
	 * @param @return
	 * @return ModelMap
	 * @user Administrator
	 * 2015年4月7日
	 * @throws
	 */
	@RequestMapping(value = "/addSentryBox.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addSentryBox(@RequestBody LocalStation localStation)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStationService.addLocalStation(localStation);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	

	@RequestMapping(value = "/delStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap delStationByUuid(@RequestBody List<String> uuid)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStationService.deleteStation(uuid);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/loadStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap loadStation()
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			PageInfo<LocalStation> page = new PageInfo<LocalStation>();
			page.setPageSize(Integer.MAX_VALUE);
			localStationService.queryByPage(page);
			resultMap.put(CommonContans.STRUTS_DATA, page.getData());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
}
